import {defineStore} from 'pinia'
import router from "@/routers";

const useNavStore = defineStore('nav', {
    state: () => ({
        // 上一个路由
        lastRouterPath: '',
        // 当前活动路由
        activeRouterPath: '',
        // 导航栏元素
        navList: []
    }),
    getters: {
        // 获取当前活动路由
        getActiveRouterPath: (state) => state.activeRouterPath,
        // 获取导航栏元素
        isHome: (state) => state.activeRouterPath === '/home'
    },
    actions: {
        hasLastRouter() {
            return this.lastRouterPath !== ''
        },
        setActiveRouterPath(path: string) {
            this.lastRouterPath = this.activeRouterPath
            this.activeRouterPath = path
        },
        goToHome() {
            router.push('/')
        },
        goToLastRouter() {
            router.push(this.lastRouterPath)
        }

    }

})


export default useNavStore
